Version 1.0 (07 August 2017)

Prerequisities

What to know?

  1. Basic R skills
  2. Basic Unix/Linux skills

What to bring?

  1. Bring laptop
  2. A GitHub account?

What data to work with?

Use the starwars dataset from dplyr.

suppressMessages(library(dplyr));
## Warning: package 'dplyr' was built under R version 3.4.1

Prerequisities

How to get started

  1. Start RStudio
  2. Create new R Markdown document

3. Specifiy output option

Exercise: Create a new R Markdown document in RStudio

Markdown 101

Markdown 101

  1. Headers
  2. Emphasis: bold and italics
  3. Lists: Ordered and unordered
  4. Images and links
  5. Blockquotes

A note on different Markdown flavours: GitHub, R Markdown, vanilla Markdown, …

Markdown 101: Headers

Markdown 101: Images

  1. Use ![](path/to/image.png)
  2. Use HTML <img src="path/to/image.png" style="width:200px;">
  3. Use knitr::include_graphics

From Markdown to R Markdown

R Markdown output

  1. Word
  2. PDF
  3. HTML

Exercise: Create different output documents

The YAML header

  1. Title and subtitle
  2. Author
  3. Date
  4. Output option

More details for every output option

R Markdown elements

Controlling the R output

  1. Chunk options
  2. Plot dimensions
  3. Transparency

Exercise: Show different chunk options

Tables

  1. General: How to output tables/dataframes?
  2. knitr::kable()
  3. DT::datatable

Excercise: Output a table

Tables: knitr::kable()

suppressMessages(library(knitr));
kable(starwars[1:4, 1:4])
name height mass hair_color
Luke Skywalker 172 77 blond
C-3PO 167 75 NA
R2-D2 96 32 NA
Darth Vader 202 136 none

Tables: DT::datatable()

suppressMessages(library(DT));
#DT::datatable(starwars, options = list(dom = "ftp", scrollX = TRUE, pageLength = 4));
DT::datatable(starwars[, 1:4], options = list(pageLength = 8));

Interactive plots

  1. plotly
  2. D3 in R

Load the necessary libraries:

suppressMessages(library(ggplot2));
suppressMessages(library(plotly));
## Warning: package 'plotly' was built under R version 3.4.1
suppressMessages(library(scatterD3));

Interactive plots: plotly::ggplotly()

ggplotly(ggplot(starwars, aes(x = height, y = mass, label = name)) + geom_point(), height = 5);

Interactive plots: scatterD3::scatterD3()

scatterD3(x = starwars$height, y = starwars$mass, lab = starwars$name);

Beyond interactive plots

R Markdown and shiny

Link with github